package com.chain.BrotherExchange.data.model;

import com.chain.BrotherExchange.R;
import com.chain.BrotherExchange.utils.Androids;

import java.io.Serializable;
import java.text.DecimalFormat;
import java.util.List;

public class LegalTenderOrderList extends BaseResponseModel<LegalTenderOrderList.DataBean> {

    public static class DataBean {
        /**
         * list : [{"id":28,"ad_id":3,"ad_type":1,"token_id":1,"token_name":"BTC","pay_id":3,"sell_id":54,"sell_name":"sell_name","buy_id":10,"buy_name":"buy_name","num":34.00234,"price":34.34,"fee":0,"order_id":"1000004101223600","states":1,"pay_status":0,"cancel_type":0,"created_time":"2018-06-22 18:15:58","updated_time":"2018-06-22 18:15:58"}]
         * page : 1
         * page_num : 10
         * total : 1
         */

        private int page;
        private int page_num;
        private int total;
        private List<ListBean> list;

        public int getPage() {
            return page;
        }

        public void setPage(int page) {
            this.page = page;
        }

        public int getPage_num() {
            return page_num;
        }

        public void setPage_num(int page_num) {
            this.page_num = page_num;
        }

        public int getTotal() {
            return total;
        }

        public void setTotal(int total) {
            this.total = total;
        }

        public List<ListBean> getList() {
            return list;
        }

        public void setList(List<ListBean> list) {
            this.list = list;
        }

        public static class ListBean implements Serializable {
            /**
             * id : 28
             * ad_id : 3
             * ad_type : 1
             * token_id : 1
             * token_name : BTC
             * pay_id : 3
             * sell_id : 54
             * sell_name : sell_name
             * buy_id : 10
             * buy_name : buy_name
             * num : 34.00234
             * price : 34.34
             * fee : 0
             * order_id : 1000004101223600
             * states : 1
             * pay_status : 0
             * cancel_type : 0
             * created_time : 2018-06-22 18:15:58
             * updated_time : 2018-06-22 18:15:58
             */

            private int id;
            private int ad_id;
            private int ad_type;
            private int token_id;
            private String token_name;
            private String pay_id;
            private int sell_id;
            private String sell_name;
            private int buy_id;
            private String buy_name;
            private double num;
            private double price;
            private int fee;
            private String order_id;
            private int states;
            private int pay_status;
            private int cancel_type;
            private String created_time;
            private String updated_time;
            private int appeal_id;
            private int appeal_states;

            public int getAppeal_id() {
                return appeal_id;
            }

            public int getAppeal_states() {
                return appeal_states;
            }

            public void setAppeal_id(int appeal_id) {
                this.appeal_id = appeal_id;
            }

            public void setAppeal_states(int appeal_states) {
                this.appeal_states = appeal_states;
            }

            public int getId() {
                return id;
            }

            public void setId(int id) {
                this.id = id;
            }

            public int getAd_id() {
                return ad_id;
            }

            public void setAd_id(int ad_id) {
                this.ad_id = ad_id;
            }

            public int getAd_type() {
                int myUid = Androids.LocalConfig.getUid();
                if (myUid == buy_id) { // 买家
                    return 2;
                } else { // 卖家
                    return 1;
                }
                //return ad_type;
            }

            public void setAd_type(int ad_type) {
                this.ad_type = ad_type;
            }

            public int getToken_id() {
                return token_id;
            }

            public void setToken_id(int token_id) {
                this.token_id = token_id;
            }

            public String getToken_name() {
                return token_name;
            }

            public void setToken_name(String token_name) {
                this.token_name = token_name;
            }

            public String getPay_id() {
                return pay_id;
            }

            public void setPay_id(String pay_id) {
                this.pay_id = pay_id;
            }

            public int getSell_id() {
                return sell_id;
            }

            public void setSell_id(int sell_id) {
                this.sell_id = sell_id;
            }

            public String getSell_name() {
                return sell_name;
            }

            public void setSell_name(String sell_name) {
                this.sell_name = sell_name;
            }

            public int getBuy_id() {
                return buy_id;
            }

            public void setBuy_id(int buy_id) {
                this.buy_id = buy_id;
            }

            public String getBuy_name() {
                return buy_name;
            }

            public void setBuy_name(String buy_name) {
                this.buy_name = buy_name;
            }

            public double getNum() {
                return num;
            }

            public String getNumText() {
                return new DecimalFormat("########.########").format(num);
            }

            public String getTotalPrice() {
                return new DecimalFormat("########.########").format(price * num);
            }

            public void setNum(double num) {
                this.num = num;
            }

            public double getPrice() {
                return price;
            }

            public String getPriceText() {
                return new DecimalFormat("########.########").format(price);
            }

            public void setPrice(double price) {
                this.price = price;
            }

            public int getFee() {
                return fee;
            }

            public void setFee(int fee) {
                this.fee = fee;
            }

            public String getOrder_id() {
                return order_id;
            }

            public void setOrder_id(String order_id) {
                this.order_id = order_id;
            }

            public int getStates() {
                return states;
            }

            public void setStates(int states) {
                this.states = states;
            }

            public int getPay_status() {
                return pay_status;
            }

            public void setPay_status(int pay_status) {
                this.pay_status = pay_status;
            }

            public int getCancel_type() {
                return cancel_type;
            }

            public void setCancel_type(int cancel_type) {
                this.cancel_type = cancel_type;
            }

            public String getCreated_time() {
                return created_time;
            }

            public void setCreated_time(String created_time) {
                this.created_time = created_time;
            }

            public String getUpdated_time() {
                return updated_time;
            }

            public void setUpdated_time(String updated_time) {
                this.updated_time = updated_time;
            }

            public String getDirectionText() {
                return getAd_type() == 1 ? "出售" : "购买";
            }

            public int getStateText() {
                // 等待支付
                if (getAd_type() == 1 && states == 1) {
                    return R.string.waiting_payment;
                }

                switch (states) {
                    case 1:
                        return R.string.order_state_unpaid;
                    case 2:
                        return R.string.order_state_to_be_released;
                    case 3:
                        return R.string.order_state_completed;
                }

                // 4
                return R.string.order_state_canceled;
            }

            // 显示支付:待支付状态并且为购买类型
            public boolean isShowPayment() {
                return states == 1 && getAd_type() == 2;
            }

            // 取消订单
            public boolean isShowCancelOrder() {
                return (states == 1 || states == 2) &&  appeal_states != 1 && getAd_type() == 2;
            }

            // 是否可以申诉: 待放行状态可以申诉
            public boolean isShowCanAppeal() {
                return states == 2 && appeal_states <= 0;
            }

            // 是显示取消申诉:
            public boolean isShowCancelAppeal() {
                return states == 2 && appeal_states == 1 && getAd_type() != 1;
            }

            // 显示联系买家
            public boolean isShowContactBuyer() {
                return (states == 1 || states == 2) && getAd_type() == 1;
            }

            // 显示联系卖家
            public boolean isShowContractSeller() {
                return getAd_type() == 2 && (states == 1 || states == 2);
            }

            // 显示放行
            public boolean isShowOrderRelease() {
                return getAd_type() == 1 && states == 2;
            }

            public boolean isShowActionLayout() {
                return states != 3 && states != 4;
            }
        }
    }
}
